package com.jivam.lottery.util;

import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.border.Border;

import com.jivam.lottery.model.Num;
import com.jivam.lottery.model.PeriodNum;

/**
 * 展示工具类
 * @author Jivam
 */
public class ShowUtil {
	
	/**
	 * 左右无，上下蓝<br>
	 * 历史期数面板号码框，计算统计面板结果框
	 */
	private static final Border BLUE1_1010 = BorderFactory.createMatteBorder(1,0,1,0,new Color(68,179,200));
	/**
	 * 四周蓝<br>
	 * 历史期数面板和值框，期数统计面板基数框（其他和值）
	 */
	private static final Border BLUE2 = BorderFactory.createLineBorder(new Color(45,92, 162));
	/**
	 * 右框无，其他红<br>
	 * 历史期数面板期数框
	 */
	private static final Border RED1_1110 = BorderFactory.createMatteBorder(1,1,1,0,new Color(127,0, 85));
	/**
	 * 四周红<br>
	 * 期数统计面板基数框（A,B,C,D前四值）
	 */
	private static final Border RED1 = BorderFactory.createLineBorder(new Color(127,0, 85));
	/**
	 * 四周灰框<br>
	 * 期数统计面板期数框
	 */
	private static final Border GREY1 = BorderFactory.createLineBorder(new Color(200,200,200));
	
	private static final String TYPEFACE_SONG = "宋体";
	private static final Font FONT_SB15 = new Font(TYPEFACE_SONG,Font.BOLD,15);
	private static final Font FONT_SB20 = new Font(TYPEFACE_SONG,Font.BOLD,20);
	
	/**
	 * 历史期数面板文字展示
	 * @param pn
	 * @return
	 */
	public static List<JLabel> getLabelListByPeriodNum(PeriodNum pn){
		List<JLabel> ls = new ArrayList<JLabel>();
		JLabel lb = new JLabel(pn.getId()+"",SwingConstants.CENTER);
		lb.setBorder(RED1_1110);//历史期数面板期数框
		ls.add(lb);
		lb = new JLabel(pn.getSum4()+"",SwingConstants.CENTER);
		lb.setBorder(BLUE2);//历史期数面板和值框
		ls.add(lb);
		for(int i=0;i<7;i++){
			lb = new JLabel(pn.getBit(i)+"",SwingConstants.CENTER);
			lb.setBorder(BLUE1_1010);//历史期数面板号码框
			lb.setFont(FONT_SB15);
			ls.add(lb);
		}
		return ls;
	}
	
	/**
	 * 期数统计面板文字展示
	 * @param num
	 * @return
	 */
	public static JLabel[] getLabelListByNum(Num num){
		JLabel[] ls = new JLabel[2];
		ls[0] = new JLabel(num.getNum()+"",SwingConstants.CENTER);
		if(num.getKey().length() == 1)
			ls[0].setBorder(RED1);//A,B,C,D前四值
		else
			ls[0].setBorder(BLUE2);//其他和值
		ls[0].setFont(FONT_SB20);
		
		ls[1] = new JLabel(num.getPeriod()+"",SwingConstants.CENTER);
		ls[1].setBorder(GREY1);//期数统计面板期数框
		return ls;
	}
	
	/**
	 * 计算统计面板文字展示
	 * @param pn
	 * @return
	 */
	public static JLabel getCalLabel(int pn){
		JLabel lb = new JLabel(pn+"",SwingConstants.CENTER);
		lb.setBorder(BLUE1_1010);//计算统计面板结果框
		lb.setFont(FONT_SB15);
		return lb;
	}
	
	private final static String UTAG_BEGIN = "<html><u>";
	private final static String UTAG_END = "</u></html>";
	/**
	 * 添加下划线
	 * @param label
	 */
	public static void addU(JLabel label){
		label.setText(UTAG_BEGIN+label.getText()+UTAG_END);
	}
	
	/**
	 * 去除下划线
	 * @param label
	 */
	public static void removeU(JLabel label){
		if(label.getText().startsWith(UTAG_BEGIN))
			label.setText(label.getText().replaceFirst(UTAG_BEGIN, "").replaceFirst(UTAG_END, ""));
	}


}
